package com.scqzy.shengchunqiang.sword2offer.day13;

/**
 * @Description: 剑指 Offer 57. 和为s的两个数字
 * @Author 盛春强
 * @Date 2021/8/19 17:39
 */
public class TwoSum {
    public int[] twoSum(int[] nums, int target) {
        int left = 0;
        int right = nums.length-1;
        while (left<right) {
            if (nums[left]+nums[right] == target) {
                return new int[]{nums[left],nums[right]};
            } else if (nums[left]+nums[right] < target) {
                left++;
            } else {
                right--;
            }
        }
        return new int[]{};
    }
}
